package io.renren.modules.pms.controller;

import java.util.List;
import java.util.Map;

import io.renren.modules.pms.dao.ProductAttributeCategoryDao;
import io.renren.modules.pms.entity.dto.ProductAttributeCateDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.pms.entity.ProductAttributeCategoryEntity;
import io.renren.modules.pms.service.ProductAttributeCategoryService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author LuoShun
 * @email lori6166@163.com
 * @date 2021-12-26 15:54:15
 */
@Api(tags  = "商品类型管理")
@RestController
@RequestMapping("productAttribute/category")
public class ProductAttributeCategoryController {

    @Autowired
    private ProductAttributeCategoryService productAttributeCategoryService;

    /**
     * 分页获取商品类型列表
     */
    @ApiOperation("分页获取商品类型列表")
    @GetMapping("/list")
    @RequiresPermissions("pms:productattributecategory:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = productAttributeCategoryService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 根据id获取商品类型
     */
    @ApiOperation("根据id获取商品类型")
    @GetMapping("/info/{id}")
    @RequiresPermissions("pms:productattributecategory:info")
    public R info(@PathVariable("id") Long id){
		ProductAttributeCategoryEntity productAttributeCategory = productAttributeCategoryService.getById(id);

        return R.ok().put("productAttributeCategory", productAttributeCategory);
    }

    /**
     * 新增商品类型
     */
    @ApiOperation("新增商品类型")
    @PostMapping("/create")
    @RequiresPermissions("pms:productattributecategory:save")
    public R save(@RequestBody ProductAttributeCategoryEntity productAttributeCategory){
		productAttributeCategoryService.save(productAttributeCategory);

        return R.ok();
    }

    /**
     * 修改商品类型
     */
    @ApiOperation("修改商品类型")
    @PostMapping("/update/{id}")
    @RequiresPermissions("pms:productattributecategory:update")
    public R update(@PathVariable long id,
                    @RequestBody ProductAttributeCategoryEntity productAttributeCategory){
        productAttributeCategory.setId(id);
		productAttributeCategoryService.updateById(productAttributeCategory);

        return R.ok();
    }

    /**
     * 删除商品类型
     */
    @ApiOperation("删除商品类型")
    @PostMapping("/delete/{id}")
    @RequiresPermissions("pms:productattributecategory:delete")
    public R delete(@PathVariable Long id){
		productAttributeCategoryService.delete(id);

        return R.ok();
    }

    /**
     * 获取所有商品属性分类及其下属性
     */
    @ApiOperation("获取所有商品属性分类及其下属性")
    @GetMapping(value = "/list/withAttr")
    @RequiresPermissions("pms:productattributecategory:listWithAttr")
    public R getListWithAttr() {
        List<ProductAttributeCateDTO> list = productAttributeCategoryService.getListWithAttr();
        return R.ok().put("data",list);
    }

}
